//
//  NSDictionary+MYK.m
//  ZFGT
//
//  Created by apple on 2018/1/11.
//  Copyright © 2018年 allyoubank.com. All rights reserved.
//

#import "NSDictionary+MYK.h"

@implementation NSDictionary (MYK)


//本地做删除null处理
- (NSDictionary *)myk_deleteAllNullValue
{
    NSMutableDictionary *mutableDic = [[NSMutableDictionary alloc]init];
    for (NSString *keyStr in self.allKeys) {
        
        
        if ([[self objectForKey:keyStr] isKindOfClass:[NSDictionary class]]) {
            
            NSDictionary *tem = [[self objectForKey:keyStr]  myk_deleteAllNullValue];
            [mutableDic setObject:tem forKey:keyStr];
            
        } else  if ([[self objectForKey:keyStr] isEqual:[NSNull null]] || [[self objectForKey:keyStr] isKindOfClass:[NSNull class]] || [self objectForKey:keyStr] == nil ) {
            [mutableDic setObject:@"" forKey:keyStr];
        } else{
            [mutableDic setObject:[self objectForKey:keyStr] forKey:keyStr];
        }
    }
    return mutableDic;
}



/*
 * @brief 把格式化的JSON格式的字符串转换成字典
 * @param jsonString JSON格式的字符串
 * @return 返回字典
 */
+ (NSDictionary *)myk_dictionaryWithJsonString:(NSString *)jsonString
{
    if(jsonString ==nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError* err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        return nil;
    }
    
    dic = [dic myk_deleteAllNullValue];
    
    return  dic;
    
}
@end
